package study.springcloud.config.nacos.support.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * （★）RedisTemplate 动态刷新（无法实现）
 * （1）修改 Nacos 不会动态刷新配置
 * （2）即便类使用注解 @RefreshScope 也无法实现动态刷新
 */
@RefreshScope
@Slf4j
//@Configuration
public class _2_RedisConfig {

    @Bean
    @RefreshScope
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        log.info(">>>>>>");
        log.info(">>>>>> 实例化 RedisTemplate");
        log.info(">>>>>>");

        RedisTemplate<String, Object> template = new RedisTemplate();
        template.setConnectionFactory(factory);
        template.afterPropertiesSet();
        return template;
    }
}
